﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Services;
using Ext.Net;
using InformationSystem.BLL.Core.Service;
using InformationSystem.BLL.Core.Model;

namespace InformationSystem.WebSite.Module.StuMgr
{
    public partial class StuMgr : BasePage
    {
        public ICollegeService CollegeService { get; set; }
        public IStudentService StudentService { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.AddTreeNodes();
            }
        }

        private void AddTreeNodes()
        {

            IList<ClassInfo> classinfo = CollegeService.GetClassInfoByAss(base.LoginUser);
            TreeNode root = new TreeNode();
            root.Leaf = false;
            root.NodeID = "class";
            root.Text = "班级";
            root.Expanded = true;
            foreach (var item in classinfo)
            {
                TreeNode node = new TreeNode();
                node.NodeID =item.ClassID;
                node.Text = item.ClassID;
                node.Leaf = true;
                root.Nodes.Add(node);
            }
            TreePanel1.Root.Add(root);
        }

        protected void NodeClick(object sender, DirectEventArgs e)
        {
            if (e.ExtraParams.Count == 0) return;
            string classid = e.ExtraParams["cid"];
            StuStore.DataSource=StudentService.GetStudentList(classid, base.LoginUser);
            StuStore.DataBind();

        }

        protected void GridViewClick(object sender, DirectEventArgs e)
        {
            if (e.ExtraParams.Count == 0) return;
            string stuid = e.ExtraParams["sid"];

            StudentInfo studentinfo = StudentService.GetStudentInfo(stuid, base.LoginUser);
            this.College.Text = studentinfo.CollegeName.ToString();
            this.Grade.Text = studentinfo.GradeID.ToString();
            this.Major.Text = studentinfo.MarjorName.ToString();
            this.Class.Text = studentinfo.ClassID.ToString();
            this.ID.Text = studentinfo.UserID.ToString();
            this.Name.Text = studentinfo.UserName.ToString();

            StuMarkStore.DataSource = StudentService.GetStudentMarkList(stuid, base.LoginUser);
            StuMarkStore.DataBind();            
           
        }    

        protected override bool CommitPermissionCheck()
        {
            throw new NotImplementedException();
        }
    }
}